package com.ffox.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;


//过滤向eureka发送的请求
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .csrf(csrf -> csrf.disable())  // 禁用CSRF（Eureka客户端不需要）
                .authorizeHttpRequests(auth -> auth
                        .requestMatchers("/eureka/**").permitAll()  // Eureka相关接口免认证
                        .anyRequest().authenticated()               // 其他所有请求需要认证
                )
                .httpBasic(basic -> {});  // 启用HTTP Basic认证

        return http.build();
    }
}